package com.lili.member.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.lili.common.result.Result;
import com.lili.member.bean.MemberPointsHistory;
import com.lili.member.service.MemberPointsHistoryService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;

@RestController
@RequestMapping("/jf")
@Api(tags = "会员积分管理")
public class MemberPointsHistoryController {
    @Autowired
    MemberPointsHistoryService memberPointsHistoryService;
    @ApiOperation(value = "查询会员积分")
    @PostMapping("/query")
    public Result queryMemberPointsHistory(@RequestBody Map map) {
        int current = 1;
        int pageSize = 10;
        if (map.get("current") != null) {
            current = Integer.parseInt(map.get("current").toString());
        }
        if (map.get("pageSize") != null) {
            pageSize = Integer.parseInt(map.get("pageSize").toString());
        }
        Page<MemberPointsHistory> page = memberPointsHistoryService.queryByPage(current, pageSize,map);
        return Result.ok(page);
    }

    @ApiOperation(value = "新增会员积分")
    @PostMapping("/save")
    public Result saveMemberPointsHistory(@RequestBody MemberPointsHistory memberPointsHistory){
        int rs=memberPointsHistoryService.save(memberPointsHistory);
        return rs== 1 ? Result.ok() : Result.fail();
    }
}
